var $;
layui.use(['layer', 'form', 'table', 'jquery', 'laydate'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    $ = layui.jquery;
    var laydate = layui.laydate;
    laydate.render({
        elem: '#unsealDate',
        type: 'date',
        trigger: 'click'
    });
    //加载表格
    getTable();

    function getTable() {
        $.ajax({
            url: '/unseal/getUnseal',
            type: 'post',
            dataType: 'json',
            data: {'type': 1},
            success: function (data) {
                tablereload(data.data);
            }
        });
    }

    function tablereload(data) {
        table.render({
            elem: '#table',
            title: '解封日志',
            data: data,
            toolbar: '#log',
            page: {
                limit: 10,
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: "首页",
                last: "尾页",
            },
            cols: [[
                {type: 'checkbox', with: 50, fixed: 'left'},
                {
                    field: '', title: '序号', align: 'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }
                },
                {field: 'account', title: '用户账号', align: 'center'},
                {field: 'nickname', title: '用户昵称', align: 'center'},
                {field: 'unsealDate', title: '解封时间', align: 'center'},
                {field: 'remarks', title: '解封原因', align: 'center'},
                {
                    fiele: '', title: '操作', align: 'center', templet: function (data) {
                        return "<div><a href='javascript:deleteUnsealLog(" + data.id + ");' style='margin-right: 10px;color: #009688'>删除</a></div>";
                    }
                }
            ]]
        });
    }

    //删除
    deleteUnsealLog = function deleteUnsealLog(id) {
        layer.confirm('是否删除该条数据', {
                icon: 3, title: '提示'
            },
            function (index) {
                //通过id删除表格数据
                $.ajax({
                    url: '/unseal/deleteUnsealLog',
                    type: 'post',
                    dataType: 'json',
                    data: {'id': id},
                    success: function (data) {
                        getTable();
                        layer.msg("删除成功");
                    }
                });
            }
        );
    }
    //搜索
    form.on('submit(search)', function (data) {
        $.ajax({
            url: '/unseal/getUnseal?type=1',
            type: 'post',
            dataType: 'json',
            data: data.field,
            success: function (data) {
                tablereload(data.data);
            }
        });
    });
});

//返回
function goBack() {
    //通过页面查找iframe
    parent.$('#recordLog').val($('#unsealLog').text());
    parent.before();
    return false;
}